;
define(["MComponent", "MPanel"], function(MComponent, MPanel) {
	/**
	 * 面板
	 * @param {Object} background 背景
	 */
	var MList = function(background) {
		this.dom = this.query("<div></div>", "MList");
		this.setBackground(background);
		var components = [];
		var styles = [];
		//垂直显示
		var display = "VERTICAL";

		var scrollflag = true;

		this.setScrollflag = function(flag) {
			scrollflag = flag;
		}

		/**
		 * 放入一个面板
		 */
		this.put = function(panel, width, height) {
			if(!panel) {
				if(!width && !height){
					throw "放入的元素不能为NULL或者Undefined!";
				}
			}
			var container = null;
			if(!(panel instanceof MComponent)) {
				container = new MPanel();
				container.setContent(panel);
				container.setWidth(width);
				container.setHeight(height);
			} else {
				container = panel;
			}
			container.mwidth = container.getWidth();
			container.mheight = container.getHeight();
			this.refresh(container);
			
			container.mindex = components.length;
			components[components.length] = container;
			this.append(container);
			return container;
		};
		
		this.size = function(){
			return components.length;
		}

		/**
		 * 设置显示状态
		 * 值：HORIZONTAL 水平
		 * 值：VERTICAL 垂直
		 */
		this.setDisplay = function(value) {
			display = value;
			for(var i in components) {
				this.refresh(components[i]);
			}
		}

		/**
		 * 获得组件宽度
		 */
		this.getCompentWidth = function() {
			var width = 0;

			for(var i in components) {
				width += components[i].mwidth;
			}
			return width;
		}

		/**
		 * 获得组件高度
		 */
		this.getCompentHeight = function() {
			var height = 0;

			for(var i in components) {
				height += components[i].mheight;
			}
			return height;
		}

		/**
		 * 更新内容
		 */
		this.refresh = function(container) {
			if(display == 'VERTICAL') {
				this.addVerticalStyles();
				container.setWidth(this.getWidth());
				container.setHeight(container.mheight);
				container.setStyle("display", "block");
			} else {
				this.addHorizontalStyles();
				container.setWidth(container.mwidth);
				container.setHeight(this.getHeight());
				container.setStyle("display", "inline-block");
				var that = this;
				var ie6 = function() {
					container.setStyle("display", "inline");
					container.setStyle("zoom", "1");
				}
				mofum.ieCallback(ie6, ie6, null, null, ie6);
			}
		}

		/**
		 * 添加垂直样式
		 */
		this.addVerticalStyles = function() {
			this.setScrollbarVisible(false);
			this.setStyle("white-space", "normal");
			if(scrollflag) {
				this.setYScrollbarVisible(true);
			}
		};

		/**
		 * 添加水平样式
		 */
		this.addHorizontalStyles = function() {
			this.setScrollbarVisible(false);
			this.setStyle("white-space", "nowrap");

			if(scrollflag) {
				this.setXScrollbarVisible(true);
			}
		};

		this.init();
	};
	mofum.extend(MList, MComponent);
	return MList;
});